/*
 * MainPanel.java
 *
 * Created on September 7, 2007, 1:04 PM
 */

package eo.main.gui.components;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;

import eo.descriptor.configuration.ApplicationInstance;
import eo.descriptor.entity.EntityDescriptor;
import eo.main.gui.components.tree.EntityTreeNodeAdaptor;
import eo.main.gui.components.tree.RootNode;

/**
 * 
 * @author takeshi
 */
public class MainPanel extends javax.swing.JPanel {

    private static final long serialVersionUID = 1L;

    private ApplicationInstance application;
    
    /** Creates new form MainPanel */
    public MainPanel() {
        initComponents();
    }

    protected TreeModel createTreeModel() {
        Collection<EntityDescriptor> values = application.getEntitiesDescriptors().values();
        List<EntityTreeNodeAdaptor> nodes = new ArrayList<EntityTreeNodeAdaptor>(values.size());
        for (EntityDescriptor entityDescriptor : values) {
            nodes.add(new EntityTreeNodeAdaptor(entityDescriptor, null));
        }
        TreeNode root = new RootNode(nodes);
        for (EntityTreeNodeAdaptor treeNode : nodes) {
            treeNode.setParent(root);
        }
        return new DefaultTreeModel(root);
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code
    // ">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(
                jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 232,
                Short.MAX_VALUE));
        jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 248,
                Short.MAX_VALUE));

        jTabbedPane1.addTab("Properties", jPanel1);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(
                jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 232,
                Short.MAX_VALUE));
        jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 248,
                Short.MAX_VALUE));

        jTabbedPane1.addTab("Methods", jPanel2);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(
                jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(jPanel3Layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 232,
                Short.MAX_VALUE));
        jPanel3Layout.setVerticalGroup(jPanel3Layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 248,
                Short.MAX_VALUE));

        jTabbedPane1.addTab("Data", jPanel3);

        jScrollPane2.setViewportView(jTabbedPane1);

        jScrollPane1.setViewportView(jTree1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(layout.createParallelGroup(
                javax.swing.GroupLayout.Alignment.LEADING).addGroup(
                javax.swing.GroupLayout.Alignment.TRAILING,
                layout.createSequentialGroup().addContainerGap().addComponent(
                        jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE,
                        135, Short.MAX_VALUE).addPreferredGap(
                        javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jScrollPane2,
                                javax.swing.GroupLayout.PREFERRED_SIZE, 239,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap()));
        layout
                .setVerticalGroup(layout
                        .createParallelGroup(
                                javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(
                                javax.swing.GroupLayout.Alignment.TRAILING,
                                layout
                                        .createSequentialGroup()
                                        .addContainerGap()
                                        .addGroup(
                                                layout
                                                        .createParallelGroup(
                                                                javax.swing.GroupLayout.Alignment.TRAILING)
                                                        .addComponent(
                                                                jScrollPane2,
                                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                278,
                                                                Short.MAX_VALUE)
                                                        .addComponent(
                                                                jScrollPane1,
                                                                javax.swing.GroupLayout.Alignment.LEADING,
                                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                                278,
                                                                Short.MAX_VALUE))
                                        .addContainerGap()));
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTree jTree1;
    // End of variables declaration//GEN-END:variables

}
